﻿@{
    ViewBag.Title = "UsersShow";
}

<link href="~/Content/BootstrapSouce/css/bootstrap.css" rel="stylesheet" />
<script src="~/Content/BootstrapSouce/js/jquery.min.js"></script>
<script src="~/Content/BootstrapSouce/js/bootstrap.min.js"></script>
<script src="~/Content/EasyUI/jquery.min.js"></script>
<script>
    var url = "http://localhost:63805/apis";
    $(function () {
        $.ajax({
            type: "get",
            url: url+"/Users/UsersShow",
            success: function (obj)
            {
                $("#tds").empty();
                for (var i = 0; i < obj.length; i++)
                {
                    $("#tds").append("<tr><td>" + obj[i].users_Id + "</td><td>" + obj[i].users_Name + "</td><td>" + obj[i].users_Account + "</td><td>" + obj[i].users_TEL + "</td><td>" + obj[i].users_CreateTimes + "</td><td>" + obj[i].users_IsStates + "</td><td><input type='button' value='启用' name='Qi" + i + "' onclick='Full(" + obj[i].users_Id + ")'  class='btn btn-success' /><input type='button' name='Ting" + i + "' value='停用' onclick='Stop(" + obj[i].users_Id + ")'  class='btn btn-success' /><input type='button' value='删除' onclick='Del(" + obj[i].users_Id + ")'  class='btn btn-success' /><input type='button' value='修改' onclick='Upt(" + obj[i].users_Id + ")'  class='btn btn-success'   data-toggle='modal' data-target='#modal_add_userUpts' /></td></tr>");
                    if (obj[i].users_IsStates=='已启用')
                    {
                        $("[name='Qi" + i + "']").hide();
                        $("[name='Ting" + i + "']").show();
                    }
                    if (obj[i].users_IsStates == '未启用') {
                        $("[name='Qi" + i + "']").show();
                        $("[name='Ting" + i + "']").hide();
                    }
                }
            }
        })
    })
    $(function () {

        $.ajax({
            type: "get",
            url: url+"/Users/UsersCount",
            success: function (obj) {
   
                $("#lb1").html(obj);
            }
        })
    })

    function Full(id)
    {
        $.ajax({
            type: "post",
            url: url+"/Users/UsersFull?id="+id,
            data: { users_Id: id },
            success: function (obj)
            {
                if (obj > 0) {
                    alert("启用成功,此账号可以使用");
                    location.href = '/Users/UsersShow';
                }
                else {
                    alert("失败!");
                }
            }
        })
    }


    function Stop(id) {
        $.ajax({
            type: "post",
            url: url+"/Users/UsersStop?id="+id,
            success: function (obj) {
                if (obj > 0) {
                    alert("停用成功,此账号不可以使用");
                    location.href = '/Users/UsersShow';
                }
                else {
                    alert("失败!");
                }
            }
        })
    }

    function Del(id)
    {
        $.ajax({
            type: "post",
            url: url+"/Users/UsersDel?id=" + id,
 
            success: function (obj) {
                if (obj > 0) {
                    alert("删除成功");
                    location.href = '/Users/UsersShow';
                }
                else {
                    alert("失败!");
                }
            }
        })
    }

    function Like()
    {
        var name = $("#likename").val();
        $.ajax({
            type: "get",
            url: url+"/Users/UsersLike?name=" + name,
            success: function (obj) {
                $("#tds").empty();
                for (var i = 0; i < obj.length; i++) {
                    $("#tds").append("<tr><td>" + obj[i].users_Id + "</td><td>" + obj[i].users_Name + "</td><td>" + obj[i].users_Account + "</td><td>" + obj[i].users_TEL + "</td><td>" + obj[i].users_CreateTimes + "</td><td>" + obj[i].users_IsStates + "</td><td><input type='button' value='启用' name='Qi" + i + "' onclick='Full(" + obj[i].users_Id + ")'  class='btn btn-success' /><input type='button' name='Ting" + i + "' value='停用' onclick='Stop(" + obj[i].users_Id + ")'  class='btn btn-success' /><input type='button' value='删除' onclick='Del(" + obj[i].users_Id + ")'  class='btn btn-success' /><input type='button' value='修改' onclick='Upt(" + obj[i].users_Id + ")'  class='btn btn-success'   data-toggle='modal' data-target='#modal_add_userUpts'/></td></tr>");
                    if (obj[i].users_IsStates == '已启用') {
                        $("[name='Qi" + i + "']").hide();
                        $("[name='Ting" + i + "']").show();
                    }
                    if (obj[i].users_IsStates == '未启用') {
                        $("[name='Qi" + i + "']").show();
                        $("[name='Ting" + i + "']").hide();
                    }
                }
            }
        })
    }
    function ShowAll()
    {
        location.href = '/Users/UsersShow';
    }


    function Upt(id)
    {
        $.ajax({
            type: "post",
            url: url+"/Users/UsersSelectId?id=" + id,
            success: function (obj)
            {
                $("#UptIds").val(obj[0].users_Id);
                $("#UptNames").val(obj[0].users_Name);
                $("#UptTel").val(obj[0].users_TEL);
                $("#UptPwd").val(obj[0].users_Pwd);
                if (obj[0].Roles_id == 1)
                {
                    $("input[type=radio][name=UptCheck][value=1]").attr("checked", 'checked')
                }
                if (obj[0].Roles_id == 2)
                {
                    $("input[type=radio][name=UptCheck][value=2]").attr("checked", 'checked')
                }
                if (obj[0].Roles_id == 3) {
                    $("input[type=radio][name=UptCheck][value=3]").attr("checked", 'checked');
                }
            }
        })
    }


    function UptFull()
    {
        var users_Id = $("#UptIds").val();
        var users_Name = $("#UptNames").val();
        var users_TEL = $("#UptTel").val()
        var users_Pwd = $("#UptPwd").val();
        var Roles_id = $("input[type=radio][name=UptCheck]:checked").val();
 
        $.ajax({
            type: "post",
            url: url+"/Users/UsereUpt",
            data: { users_Id: users_Id, users_Name: users_Name, users_TEL: users_TEL, users_Pwd: users_Pwd, Roles_id: Roles_id },
            success: function (obj)
            {
                if (obj > 0) {
                    alert("修改成功");
                    location.href = '/Users/UsersShow';

                }
                else {
                    alert("失败!");
                }
            }
        })
    }


</script>
<style>
    #lb2 {
    float:right;
    }
</style>
<div class="col-md-12" style="margin-top:10px;height:35px;background-color:#0094ff;" >
    <input type="button" value="添加员工" class="btn btn-primary" data-toggle="modal" data-target="#modal_add_user" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="text" id="likename" /><input type="button" value="根据名字来查询" class="btn btn-success" onclick="Like()" />         <input type="button" value="显示全部" onclick="ShowAll()" class="btn btn-primary" />  <span id="lb2" style="font-size:20px">共有<span id="lb1" style="color:red"></span>个员工</span>
</div>

<table class="table table-striped">
    <tr>
        <td>编号</td>
        <td>姓名</td>
        <td>账户</td>
        <td>常用手机</td>
        <td>创建时间</td>
        <td>是够启用</td>
        <td>操作</td>
    </tr>
    <tbody id="tds">

    </tbody>
</table>


<div class="modal fade" id="modal_add_user" tabindex="-1" role="dialog" aria-labelledby="label_course">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="label_course"><strong>添加员工</strong></h4>
            </div>
            <div class="modal-body">
                <table class="table table-striped">
                    <tr>
                        <td>员工姓名</td>
                        <td><input type="text" id="Usersname" /></td>
                    </tr>
                    <tr>
                        <td>员工账户</td>
                        <td><input type="text" id="Usersname" /></td>
                    </tr>
                    <tr>
                        <td>常用手机</td>
                        <td><input type="text" id="Usersname" /></td>
                    </tr>
                    <tr>
                    <td>角色</td>
                    <td><input type="checkbox"  name="AddCheck" value="1" />勘察&nbsp;&nbsp;<input type="checkbox" name="AddCheck" />估价&nbsp;&nbsp;<input type="checkbox" name="AddCheck" />审核</td>
                    </tr>
                </table>
             <input type="button" value="添加" class="btn btn-success" />
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                </div>
            </div>
        </div>
    </div>
</div>



<div class="modal fade" id="modal_add_userUpts" tabindex="-1" role="dialog" aria-labelledby="label_course">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="label_course"><strong>修改员工信息</strong></h4>
            </div>
            <div class="modal-body">
                <table class="table table-striped">
                    <tr>
                        <td>员工编号</td>
                        <td><input type="text" id="UptIds" disabled /></td>
                    </tr>
                    <tr>
                        <td>员工姓名</td>
                        <td><input type="text" id="UptNames" /></td>
                    </tr>
                    <tr>
                        <td>常用手机</td>
                        <td><input type="text" id="UptTel" /></td>
                    </tr>
                    <tr>
                        <td>登陆密码</td>
                        <td><input type="text" id="UptPwd" /></td>
                    </tr>
                    <tr>
                        <td>角色</td>
                        <td><input type="radio" name="UptCheck" value="1" />勘察&nbsp;&nbsp;<input type="radio" name="UptCheck" value="2" />估价&nbsp;&nbsp;<input type="radio" name="UptCheck" value="3" />审核</td>
                    </tr>
                </table>
                <input type="button" value="修改"  onclick="UptFull()"/>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                </div>
            </div>
        </div>
    </div>
</div>

